class AgeError(Exception):#继承Expection类
    def __init__(self):
        super().__init__("父亲应该比儿子大")
        #可以思考之前继承时所用，使用父类的初始化方式，初始化错误信息，当报错时输出错误信息

def compare(dadage,mineage):
    if dadage <= mineage:
        raise AgeError
    else:
        print(f"父亲:{dadage},自己:{mineage}")

dadage1 = 3
mineage1 = 2
compare(dadage1,mineage1)
#父亲:3,自己:2

dadage2 = 1
mineage2 = 2
compare(dadage2,mineage2)
#AgeError: 父亲应该比儿子大










